/**********************************************************************
 * Project : WoWGuildRoster (http://www.codeplex.com/WowGuildRoster/)
 * Module  : DotNetWarcraft.WoWGuildRoster.UI.DNN.WGR_ViewRoster
 **********************************************************************
 * 
 * 
 * 
 **********************************************************************
 * License : All code is subject to licensing terms per the Microsoft
 *   Permissive License (Ms-PL) v1.1. For full license information,
 *   refer to the packaged license.txt file.
 **********************************************************************
 * Revision History:
 * -----------------
 * 2007-08-26 -- Cliff Simpkins: Initial Version
 * 2007-09-02 -- Cliff Simpkins: Added Officer/Member visibility props
 *                 and adding logic for error message label
 * 2008-12-24 -- Cliff Simpkins: Moving the settings variables to class
 *                 level, and adding settings to build out the lists
 *                 at runtime
 **********************************************************************
 */
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Exceptions;

using WGR_Business = DotNetWarcraft.WoWGuildRoster.Business;
using DotNetWarcraft.WoWGuildRoster.Business;


namespace DotNetWarcraft.WoWGuildRoster.UI.DNN {
  public partial class WGR_ViewRoster : PortalModuleBase, IActionable, IPortable, ISearchable {
    #region "Private Variables"
    protected bool _isInMemberRole, _isInOfficerRole;

    protected bool _settingsLoaded = false;
    protected String _displayType = "";
    protected int _rowCount = -1;
    protected int _listsPerRowCount = -1;
    protected bool _showMainsOnly = false;
    protected bool _armoryColsOnly = false;
    #endregion
    #region "Public Properties"
    public bool IsInMemberRole {
      get {
        try {
          if (this.IsInOfficerRole) {
            return true;
          } else {
            return Convert.ToBoolean(this.ViewState[WGR_Business.WGRDnnConstants.VIEWSTATE_IS_IN_MEMBER_ROLE].ToString());
          }
        } catch {
          return false;
        }
      }
    }
    public bool IsInOfficerRole {
      get {
        try {
          return Convert.ToBoolean(this.ViewState[WGR_Business.WGRDnnConstants.VIEWSTATE_IS_IN_OFFICER_ROLE].ToString());
        } catch {
          return false;
        }
      }
    }

    public String RosterErrorMessage {
      set {
        if (value == "") {
          lblErrorMsg.Visible = false;
        } else {
          lblErrorMsg.Visible = true;
        }
        lblErrorMsg.Text = value;
      }
    }
    #endregion
    #region "Protected Properties"
    protected int PageSetting_ListsPerRowCount {
      get {
        if (!_settingsLoaded) {
          this.LoadPageSettingsFromDnn();
        }
        return _listsPerRowCount;
      }
    }
    protected int PageSetting_RowCount {
      get {
        if (!_settingsLoaded) {
          this.LoadPageSettingsFromDnn();
        }
        return _rowCount;
      }
    }
    protected bool PageSetting_ShowMainsOnly {
      get {
        if (!_settingsLoaded) {
          this.LoadPageSettingsFromDnn();
        }
        return _showMainsOnly;
      }
    }
    protected bool PageSetting_ArmoryColsOnly {
      get {
        if (!_settingsLoaded) {
          this.LoadPageSettingsFromDnn();
        }
        return _armoryColsOnly;
      }
    }
    protected String PageSetting_DisplayType {
      get {
        if (!_settingsLoaded) {
          this.LoadPageSettingsFromDnn();
        }
        return _displayType;
      }
    }

    protected int DnnSetting_ListsPerRowCount {
      get {
        int _rowCount = WGR_Business.WGRDnnConstants.SETTING_DEFAULT_LISTS_PER_ROW;

        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_LISTS_PER_ROW)) {
          int _outVal;
          if (int.TryParse(Settings[WGR_Business.WGRDnnConstants.SETTING_LISTS_PER_ROW].ToString(), out _outVal)) {
            _rowCount = _outVal;
          }
        }
        return _rowCount;
      }
    }
    protected int DnnSetting_RowCount {
      get {
        int _rowCount = WGR_Business.WGRDnnConstants.SETTING_DEFAULT_LINES_PER_PAGE;

        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_LINES_PER_PAGE)) {
          int _outVal;
          if (int.TryParse(Settings[WGR_Business.WGRDnnConstants.SETTING_LINES_PER_PAGE].ToString(), out _outVal)) {
            _rowCount = _outVal;
          }
        }
        return _rowCount;
      }
    }
    protected int DnnSetting_LevelRange_Min {
      get {
        int _minLevel = WGR_Business.WGRDnnConstants.SETTING_DEFAULT_MINLEVEL;

        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_DISPLAY_MINLEVEL)) {
          int _outVal;
          if (int.TryParse(Settings[WGR_Business.WGRDnnConstants.SETTING_DISPLAY_MINLEVEL].ToString(), out _outVal)) {
            _minLevel = _outVal;
          }
        }
        return _minLevel;
      }
    }
    protected int DnnSetting_LevelRange_Max {
      get {
        int _maxLevel = WGR_Business.WGRDnnConstants.SETTING_DEFAULT_MAXLEVEL;

        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_DISPLAY_MAXLEVEL)) {
          int _outVal;
          if (int.TryParse(Settings[WGR_Business.WGRDnnConstants.SETTING_DISPLAY_MAXLEVEL].ToString(), out _outVal)) {
            _maxLevel = _outVal;
          }
        }
        return _maxLevel;
      }
    }
    protected int DnnSetting_GRankRange_Min {
      get {
        int _minGRank = WGR_Business.WGRDnnConstants.SETTING_DEFAULT_MINGRANK;

        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_DISPLAY_MINGRANK)) {
          int _outVal;
          if (int.TryParse(Settings[WGR_Business.WGRDnnConstants.SETTING_DISPLAY_MINGRANK].ToString(), out _outVal)) {
            _minGRank = _outVal;
          }
        }
        return _minGRank;
      }
    }
    protected int DnnSetting_GRankRange_Max {
      get {
        int _maxGRank = WGR_Business.WGRDnnConstants.SETTING_DEFAULT_MAXGRANK;

        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_DISPLAY_MAXGRANK)) {
          int _outVal;
          if (int.TryParse(Settings[WGR_Business.WGRDnnConstants.SETTING_DISPLAY_MAXGRANK].ToString(), out _outVal)) {
            _maxGRank = _outVal;
          }
        }
        return _maxGRank;
      }
    }
    protected bool DnnSetting_ShowMainsOnly {
      get {
        bool _showMainsOnly = false;
        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_MAINS_ONLY)) {
          int _outValue = 0;

          if (int.TryParse(Settings[WGR_Business.WGRDnnConstants.SETTING_MAINS_ONLY].ToString(), out _outValue)) {
            _showMainsOnly = ((_outValue == 1) ? true : false);
          } else { _showMainsOnly = false; }

        } else {
          _showMainsOnly = false;
        }
        return _showMainsOnly;
      }
    }
    protected bool DnnSetting_ArmoryColsOnly {
      get {
        bool _armoryColsOnly = false;
        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_ARMORY_STYLE_COLS)) {
          int _outValue = 0;

          if (int.TryParse(Settings[WGR_Business.WGRDnnConstants.SETTING_ARMORY_STYLE_COLS].ToString(), out _outValue)) {
            _armoryColsOnly = ((_outValue == 1) ? true : false);
          } else { _armoryColsOnly = false; }

        } else {
          _armoryColsOnly = false;
        }
        return _armoryColsOnly;
      }
    }
    protected String DnnSetting_DisplayType {
      get {
        String _displayType = "";

        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_DISPLAY_TYPE)) {
          _displayType = Settings[WGR_Business.WGRDnnConstants.SETTING_DISPLAY_TYPE].ToString();
        } else {
          _displayType = WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_ALL_CLASSES;
        }
        return _displayType;
      }
    }
    protected String DnnSetting_DisplayOneClass {
      get {
        String _displayClass = "";
        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_DISPLAY_CLASS)) {
          _displayClass = Settings[WGR_Business.WGRDnnConstants.SETTING_DISPLAY_CLASS].ToString();
        }
        return _displayClass;
      }
    }
    protected String DnnSetting_DisplayOneGuildRank {
      get {
        String _displayRank = "";
        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_DISPLAY_RANK)) {
          _displayRank = Settings[WGR_Business.WGRDnnConstants.SETTING_DISPLAY_RANK].ToString();
        }
        return _displayRank;
      }
    }
    protected String DnnSetting_DisplayOneProf {
      get {
        String _displayProf = "";
        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_DISPLAY_PROF)) {
          _displayProf = Settings[WGR_Business.WGRDnnConstants.SETTING_DISPLAY_PROF].ToString();
        }
        return _displayProf;
      }
    }
    protected String DnnSetting_DisplayOneRep {
      get {
        String _displayRep = "";
        if (Settings.Contains(WGR_Business.WGRDnnConstants.SETTING_DISPLAY_REPUTATION)) {
          _displayRep = Settings[WGR_Business.WGRDnnConstants.SETTING_DISPLAY_REPUTATION].ToString();
        }
        return _displayRep;
      }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e) {
      //Version name is first line to force the proper controller :)
      this.hlDNW_WGR_site.Text = WGR_Business.DnnGuildRosterController.ApplicationName;
      this.hlDNW_WGR_site.NavigateUrl = this.EditUrl("About");
      this.SetVisibility_PageAdmin();
      this.SetVisibility_FromSettings();

      if (DotNetNuke.Framework.AJAX.IsInstalled()) {
        DotNetNuke.Framework.AJAX.RegisterScriptManager();
      }

    }

    protected void SetVisibility_PageAdmin() {
      pnlAdminOptions.Visible = this.IsEditable;

      if (pnlAdminOptions.Visible) {
        this.lbControlPanel.NavigateUrl = this.EditUrl("ControlPanel");
      }
    }

    protected bool ErrorCheck_NoRostersInSystem() {
      List<WGR_Business.GuildRoster> _rostersSystem = WGR_Business.DnnGuildRosterController.GetRosters();
      if (_rostersSystem.Count < 1) {
        lblErrorMsg.Visible = true;
        String _errMsg = "ERROR WGR-001: ";
          _errMsg += Localization.GetString("ErrorMsg-NoRostersAvail", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
        if (this.IsEditable) {
          _errMsg += Localization.GetString("ErrorMsg-NoRostersAvail-ToFix", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
          _errMsg = _errMsg.Replace("{ControlPanelURL}", this.EditUrl("ControlPanel"));
        } else {
          _errMsg += Localization.GetString("ErrorMsg-NoRosters-User", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
        }
        lblErrorMsg.Text = _errMsg;
        return true;
      }
      return false;
    }
    protected bool ErrorCheck_NoRostersSelected() {
      List<WGR_Business.GuildRosterModule> _rostersModule = WGR_Business.DnnGuildRosterController.GetRostersByModule(this.ModuleId, this.PortalId);
      if (_rostersModule.Count < 1) {
        lblErrorMsg.Visible = true;
        String _errMsg = "ERROR WGR-002: ";
        _errMsg += Localization.GetString("ErrorMsg-NoRostersSet", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
        if (this.IsEditable) {
          _errMsg += Localization.GetString("ErrorMsg-NoRostersSet-ToFix", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
          _errMsg = _errMsg.Replace("{SettingsURL}", Globals.NavigateURL(this.TabId, "Module", "ModuleId=" + this.ModuleId.ToString()));
        } else {
          _errMsg += Localization.GetString("ErrorMsg-NoRosters-User", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
        }
        lblErrorMsg.Text = _errMsg;
        return true;
      }
      return false;
    }

    protected bool ErrorCheck_NoRostersValid() {
      int _validRoster = 0;

      List<WGR_Business.GuildRosterModule> _rostersModule = WGR_Business.DnnGuildRosterController.GetRostersByModule(this.ModuleId, this.PortalId);
      foreach (WGR_Business.GuildRosterModule _rm in _rostersModule) {
        try {
          WGR_Business.GuildRoster _roster = WGR_Business.DnnGuildRosterController.GetRoster(_rm.Roster_ID);
          if (_roster.Guild_Name != "") { _validRoster++; }
        } catch {
        }
      }

      if (_validRoster < 1) {
        lblErrorMsg.Visible = true;
        String _errMsg = "ERROR WGR-003: ";
        _errMsg += Localization.GetString("ErrorMsg-NoRostersValid", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
        if (this.IsEditable) {
          _errMsg += Localization.GetString("ErrorMsg-NoRostersValid-ToFix", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
          _errMsg = _errMsg.Replace("{SettingsURL}", Globals.NavigateURL(this.TabId, "Module", "ModuleId=" + this.ModuleId.ToString()));
        } else {
          _errMsg += Localization.GetString("ErrorMsg-NoRosters-User", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
        }
        lblErrorMsg.Text = _errMsg;
        return true;
      }
      return false;
    }

    protected bool ErrorCheck_NoRostersHaveData() {
      int _charCount = 0;

      List<WGR_Business.GuildRosterModule> _rostersModule = WGR_Business.DnnGuildRosterController.GetRostersByModule(this.ModuleId, this.PortalId);
      foreach (WGR_Business.GuildRosterModule _rm in _rostersModule) {
        try {
          List<WGR_Business.GuildEntry> _chars = WGR_Business.DnnGuildRosterController.GetCharEntries(_rm.Roster_ID);
          if (_chars != null) { _charCount += _chars.Count; }
        } catch {
        }
      }

      if (_charCount < 1) {
        lblErrorMsg.Visible = true;
        String _errMsg = "ERROR WGR-004: ";
        _errMsg += Localization.GetString("ErrorMsg-NoCharsInRosters", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
        if (this.IsEditable) {
          _errMsg += Localization.GetString("ErrorMsg-NoCharsInRosters-ToFix", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
          _errMsg = _errMsg.Replace("{InstallURL}", WGRDnnConstants.DNW_WGR_DNN_URL_CONFIG);
        } else {
          _errMsg += Localization.GetString("ErrorMsg-NoRosters-User", WGRDnnConstants.DNW_WGR_RESX_DIR + "WGR_ViewRoster.ascx.resx");
        }
        lblErrorMsg.Text = _errMsg;
        return true;
      }
      return false;
    }

    protected void SetVisibility_FromSettings() {
      //Setup the baseline visibility
      this.pnlListDisplay.Visible = false;
      this.pnlOneCharList.Visible = false;
      hlDNW_WGR_site.Visible = true;

      //Verify that there are rosters to process
      if (ErrorCheck_NoRostersInSystem() || ErrorCheck_NoRostersSelected() || 
          ErrorCheck_NoRostersValid() || ErrorCheck_NoRostersHaveData()) {
        return;
      }

      //Now comes the business logic application based on the settings
      switch (PageSetting_DisplayType) {
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_ALL_PROFS:
          this.BindData_ProfessionInfo();
          break;
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_NOTES:
          break;
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_ONE_CLASS:
          this.pnlOneCharList.Visible = true;
          hlDNW_WGR_site.Visible = false;

          BindCharList_Class(ref rstOneEntry, DnnSetting_DisplayOneClass);
          rstOneEntry.ShowTitle = false;
          break;
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_ONE_PROF:
          this.pnlOneCharList.Visible = true;
          hlDNW_WGR_site.Visible = false;

          BindCharList_Profession(ref rstOneEntry, DnnSetting_DisplayOneProf);
          rstOneEntry.ShowTitle = false;
          break;
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_ALL_RANKS:
          this.BindData_GuildRankInfo();
          break;
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_BY_RANKS_ALL:
          this.pnlOneCharList.Visible = true;
          hlDNW_WGR_site.Visible = false;
          rstOneEntry.ShowTitle = false;

          rstOneEntry.LoadType = WGR_CharList.RosterLoadType.LoadByGRankAll;
          break;
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_BY_RANKS_RANGE:
          this.pnlOneCharList.Visible = true;
          hlDNW_WGR_site.Visible = false;
          rstOneEntry.ShowTitle = false;

          rstOneEntry.LoadType = WGR_CharList.RosterLoadType.LoadByGRankRange;
          rstOneEntry.MinLevel = DnnSetting_GRankRange_Min;
          rstOneEntry.MaxLevel = DnnSetting_GRankRange_Max;

          break;
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_ONE_RANK:
          this.pnlOneCharList.Visible = true;
          hlDNW_WGR_site.Visible = false;
          rstOneEntry.ShowTitle = false;

          BindCharList_GuildRank(ref rstOneEntry, DnnSetting_DisplayOneGuildRank);
          rstOneEntry.ShowTitle = false;
          break;
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_BY_LEVEL_ALL:
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_BY_LEVEL_RANGE:
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_BY_LEVEL_RANGE_ALPHA:
          this.pnlOneCharList.Visible = true;
          hlDNW_WGR_site.Visible = true;

          rstOneEntry.Title = "";
          if (_displayType == WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_BY_LEVEL_ALL) {
            rstOneEntry.LoadType = WGR_CharList.RosterLoadType.LoadByLevelAll;
          } else {
            if (_displayType == WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_BY_LEVEL_RANGE) {
              rstOneEntry.LoadType = WGR_CharList.RosterLoadType.LoadByLevelRange;
            } else if (_displayType == WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_BY_LEVEL_RANGE_ALPHA) {
              rstOneEntry.LoadType = WGR_CharList.RosterLoadType.LoadByLevelRangeAlpha;
            }
            rstOneEntry.MinLevel = DnnSetting_LevelRange_Min;
            rstOneEntry.MaxLevel = DnnSetting_LevelRange_Max;
          }
          rstOneEntry.ShowTitle = false;

          //this.lblOneCharListNotYet.Visible = true;
          break;
        case WGR_Business.WGRDnnConstants.ROSTER_DISPLAYTYPE_ALL_CLASSES:
        default:
          this.BindData_ClassInfo();
          break;
      }
      //Initialize values for the one entry panel
      rstOneEntry.ParentModuleID = this.ModuleId;
      rstOneEntry.ParentPortalID = this.PortalId;
      rstOneEntry.ListSize = PageSetting_RowCount;
      rstOneEntry.ShowMainsOnly = PageSetting_ShowMainsOnly;
      rstOneEntry.ArmoryColsOnly = PageSetting_ArmoryColsOnly;

    }
    protected void BindData_GetClassList(ref List<WGR_CharList> classList, String classDbName) {
      BindData_GetClassList(ref classList, classDbName, classDbName);
    }
    protected void BindData_GetClassList(ref List<WGR_CharList> classList, String classDbName, String classDisplayName) {
      WGR_CharList _rstClassList = null;

      int _count = WGR_Business.DnnGuildRosterController.GetCharEntriesByClass_Count(this.ModuleId, this.PortalId, classDbName, PageSetting_ShowMainsOnly);

      if (_count > 0) {
        _rstClassList = (WGR_CharList)this.LoadControl("WGR_CharList.ascx");
        BindCharList_Class(ref _rstClassList, classDbName, classDisplayName);
      }

      if (_rstClassList != null) { classList.Add(_rstClassList); }
    }

    protected void BindData_GetProfList(ref List<WGR_CharList> profList, String profDbName) {
      BindData_GetProfList(ref profList, profDbName, profDbName);
    }
    protected void BindData_GetProfList(ref List<WGR_CharList> profList, String profDbName, String profDisplayName) {
      WGR_CharList _rstProfList = null;

      int _count = WGR_Business.DnnGuildRosterController.GetEntryStatsLIs_ByProfession_Count(this.ModuleId, this.PortalId, profDbName, PageSetting_ShowMainsOnly);

      if (_count > 0) {
        _rstProfList = (WGR_CharList)this.LoadControl("WGR_CharList.ascx");
        BindCharList_Profession(ref _rstProfList, profDbName, profDisplayName);
      }

      if (_rstProfList != null) { profList.Add(_rstProfList); }
    }

    protected void BindData_GetGuildRankList(ref List<WGR_CharList> grList, int gRank) {
      BindData_GetGuildRankList(ref grList, gRank, gRank.ToString());
    }
    protected void BindData_GetGuildRankList(ref List<WGR_CharList> grList, int gRank, String gRankTitle) {
      WGR_CharList _rstGRankList = null;

      int _count = WGR_Business.DnnGuildRosterController.GetCharEntriesByGuildRank_Count(this.ModuleId, this.PortalId, gRank, PageSetting_ShowMainsOnly);

      if (_count > 0) {
        _rstGRankList = (WGR_CharList)this.LoadControl("WGR_CharList.ascx");
        BindCharList_GuildRank(ref _rstGRankList, gRank.ToString(), gRankTitle);
      }

      if (_rstGRankList != null) { grList.Add(_rstGRankList); }
    }
    protected void DispPane_AddListsToDisplayPane(ref List<WGR_CharList> pList) {
      DispPane_AddListsToDisplayPane(ref pList, false);
    }
    protected void DispPane_AddListsToDisplayPane(ref List<WGR_CharList> pList, bool centerFirstRow) {
      int _renderedLists = 0;
      bool _firstRowProcessed = false;

      HtmlTable _listTable = new HtmlTable();
      pnlListDisplay.Controls.Add(_listTable);
      pnlListDisplay.Visible = true;

      HtmlTableRow _currRow = null;
      HtmlTableCell _currCell = null;
      Double _width = 100.0 / Convert.ToDouble(PageSetting_ListsPerRowCount);

      foreach (PortalModuleBase p in pList) {
        if (_renderedLists % PageSetting_ListsPerRowCount == 0) {
          _currRow = new HtmlTableRow();
          _listTable.Rows.Add(_currRow);
        }

        _currCell = new HtmlTableCell();
        _currCell.Width = _width.ToString("F1") + "%";
        _currCell.VAlign = "top";
        _currRow.Cells.Add(_currCell);
        _currCell.Controls.Add(p);
        if (centerFirstRow && !_firstRowProcessed) {
          _firstRowProcessed = true;
          DispPane_CenterHtmlRow(ref _listTable, ref _currRow, ref _currCell);
        } else {
          _renderedLists++;
        }
      }

      //Now that we have the table rows populated, lets fill up any missing cells
      DispPane_CenterHtmlRow(ref _listTable, ref _currRow, ref _currCell);

    }
    protected void DispPane_CenterHtmlRow(ref HtmlTable table, ref HtmlTableRow currRow, ref HtmlTableCell currCell) {
      Double _width = 100.0 / Convert.ToDouble(PageSetting_ListsPerRowCount);

      if (currRow != null) {
        while (currRow.Cells.Count < PageSetting_ListsPerRowCount) {
          //First we add a cell to the end of the row
          if (currRow.Cells.Count < PageSetting_ListsPerRowCount) {
            currCell = new HtmlTableCell();
            currCell.Width = _width.ToString("F1") + "%";
            currRow.Cells.Add(currCell);
          }
          //I we're still short on cells, we add a cell to the beginning of the row
          if (currRow.Cells.Count < PageSetting_ListsPerRowCount) {
            currCell = new HtmlTableCell();
            currCell.Width = _width.ToString("F1") + "%";
            currRow.Cells.Insert(0, currCell);
          }
        }
      }

    }

    protected void BindData_ClassInfo() {
      List<WGR_CharList> _classes = new List<WGR_CharList>();

      BindData_GetClassList(ref _classes, "Druid", Localization.GetString("List-Druid", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetClassList(ref _classes, "Hunter", Localization.GetString("List-Hunter", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetClassList(ref _classes, "Mage", Localization.GetString("List-Mage", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetClassList(ref _classes, "Paladin", Localization.GetString("List-Paladin", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetClassList(ref _classes, "Priest", Localization.GetString("List-Priest", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetClassList(ref _classes, "Rogue", Localization.GetString("List-Rogue", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetClassList(ref _classes, "Shaman", Localization.GetString("List-Shaman", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetClassList(ref _classes, "Warlock", Localization.GetString("List-Warlock", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetClassList(ref _classes, "Warrior", Localization.GetString("List-Warrior", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetClassList(ref _classes, "DeathKnight", Localization.GetString("List-DeathKnight", WGRDnnConstants.DNW_WGR_RESX_GENERAL));

      DispPane_AddListsToDisplayPane(ref _classes);
    }

    protected void BindData_ProfessionInfo() {
      List<WGR_CharList> _profs = new List<WGR_CharList>();

      BindData_GetProfList(ref _profs, "Alchemy", Localization.GetString("List-Alchemy", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetProfList(ref _profs, "Blacksmithing", Localization.GetString("List-Blacksmithing", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetProfList(ref _profs, "Enchanting", Localization.GetString("List-Enchanting", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetProfList(ref _profs, "Engineering", Localization.GetString("List-Engineering", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetProfList(ref _profs, "Inscription", Localization.GetString("List-Inscription", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetProfList(ref _profs, "Jewelcrafting", Localization.GetString("List-Jewelcrafting", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetProfList(ref _profs, "Leatherworking", Localization.GetString("List-Leatherworking", WGRDnnConstants.DNW_WGR_RESX_GENERAL));
      BindData_GetProfList(ref _profs, "Tailoring", Localization.GetString("List-Tailoring", WGRDnnConstants.DNW_WGR_RESX_GENERAL));

      DispPane_AddListsToDisplayPane(ref _profs);
    }

    protected void BindData_GuildRankInfo() {
      List<WGR_CharList> _ranks = new List<WGR_CharList>();

      List<GuildRoster> _guilds = DnnGuildRosterController.GetRosters(this.ModuleId, this.PortalId);

      //We will add the guild rank title from the first guild only
      BindData_GetGuildRankList(ref _ranks, 0, _guilds[0].GuildRank0);
      BindData_GetGuildRankList(ref _ranks, 1, _guilds[0].GuildRank1);
      BindData_GetGuildRankList(ref _ranks, 2, _guilds[0].GuildRank2);
      BindData_GetGuildRankList(ref _ranks, 3, _guilds[0].GuildRank3);
      BindData_GetGuildRankList(ref _ranks, 4, _guilds[0].GuildRank4);
      BindData_GetGuildRankList(ref _ranks, 5, _guilds[0].GuildRank5);
      BindData_GetGuildRankList(ref _ranks, 6, _guilds[0].GuildRank6);
      BindData_GetGuildRankList(ref _ranks, 7, _guilds[0].GuildRank7);
      BindData_GetGuildRankList(ref _ranks, 8, _guilds[0].GuildRank8);
      BindData_GetGuildRankList(ref _ranks, 9, _guilds[0].GuildRank9);

      DispPane_AddListsToDisplayPane(ref _ranks, true);
    }

    protected void BindCharList_Class(ref WGR_CharList listToBind, String className) {
      //Overloaded method - we don't want to display a custom title/header
      BindCharList_Class(ref listToBind, className, className);
    }
    protected void BindCharList_Class(ref WGR_CharList listToBind, String className, String displayName) {
      BindCharList(ref listToBind, WGR_CharList.RosterLoadType.LoadCharClass, className, displayName);
    }

    protected void BindCharList_GuildRank(ref WGR_CharList listToBind, String rankNum) {
      BindCharList(ref listToBind, WGR_CharList.RosterLoadType.LoadGuildRank, rankNum);
    }
    protected void BindCharList_GuildRank(ref WGR_CharList listToBind, String rankNum, String displayName) {
      BindCharList(ref listToBind, WGR_CharList.RosterLoadType.LoadGuildRank, rankNum, displayName);
    }

    protected void BindCharList_Profession(ref WGR_CharList listToBind, String profName) {
      BindCharList(ref listToBind, WGR_CharList.RosterLoadType.LoadCharProfession, profName, profName);
    }
    protected void BindCharList_Profession(ref WGR_CharList listToBind, String profName, String displayName) {
      BindCharList(ref listToBind, WGR_CharList.RosterLoadType.LoadCharProfession, profName, displayName);
    }
    protected void BindCharList_Reputation(ref WGR_CharList listToBind, String repName) {
      BindCharList(ref listToBind, WGR_CharList.RosterLoadType.LoadCharReputation, repName);
    }

    protected void BindCharList(ref WGR_CharList listToBind, WGR_CharList.RosterLoadType loadType, String loadValue) {
      //Overloaded method - we don't want to display a custom title/header
      BindCharList(ref listToBind, loadType, loadValue, loadValue);
    }
    protected void BindCharList(ref WGR_CharList listToBind, WGR_CharList.RosterLoadType loadType, String loadValue, String displayTitle) {
      listToBind.Visible = true;
      listToBind.LoadType = loadType;
      listToBind.Title = loadValue;
      listToBind.DisplayTitle = displayTitle;
      listToBind.ParentModuleID = this.ModuleId;
      listToBind.ParentPortalID = this.PortalId;
      listToBind.ListSize = PageSetting_RowCount;
      listToBind.ShowMainsOnly = PageSetting_ShowMainsOnly;
      listToBind.ArmoryColsOnly = PageSetting_ArmoryColsOnly;
    }

    #region "Internal Supporting methods"
    protected void LoadPageSettingsFromDnn() {
      _displayType = DnnSetting_DisplayType;
      _rowCount = DnnSetting_RowCount;
      _listsPerRowCount = DnnSetting_ListsPerRowCount;
      _showMainsOnly = DnnSetting_ShowMainsOnly;
      _armoryColsOnly = DnnSetting_ArmoryColsOnly;

    }
    #endregion

    #region "Optional DNN Interfaces"

    public DotNetNuke.Entities.Modules.Actions.ModuleActionCollection ModuleActions {
      get {
        DotNetNuke.Entities.Modules.Actions.ModuleActionCollection Actions = new DotNetNuke.Entities.Modules.Actions.ModuleActionCollection();
        //Actions.Add(this.GetNextActionID(), Localization.GetString(DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, LocalResourceFile), DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);
        Actions.Add(this.GetNextActionID(), Localization.GetString("ControlPanel.Action", this.LocalResourceFile), "ControlPanel", "", "", this.EditUrl("ControlPanel"), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);
        return Actions;
      }
    }

    public string ExportModule(int ModuleID) {
      // included as a stub only so that the core knows this module Implements Entities.Modules.IPortable
      return null;
    }

    public void ImportModule(int ModuleID, string Content, string Version, int UserID) {
      // included as a stub only so that the core knows this module Implements Entities.Modules.IPortable
    }

    public DotNetNuke.Services.Search.SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo) {
      // included as a stub only so that the core knows this module Implements Entities.Modules.ISearchable
      return null;
    }

    #endregion

  }
}